package org.walker.iotScheduling.modules.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;

import java.util.concurrent.RejectedExecutionException;

/**
 * @author :zhuangguojin
 * @since :2024/12/4 13:56
 */
@Configuration
public class ThreadPoolTaskSchedulerConfig {

    @Bean("ThreadPoolSchedulerCommon")
    public ThreadPoolTaskScheduler threadPoolTaskScheduler() {
        ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
        scheduler.setPoolSize(5);
        scheduler.setThreadNamePrefix("my-task-scheduler-");
        scheduler.setRejectedExecutionHandler((runnable,e) -> {
            throw new RejectedExecutionException("This task scheduler is busy!");
        });
        return scheduler;
    }

}
